/*
Brick And Blast, a crossplatform breakout game.
 Copyright (C) 2008-2010 Julien CLEMENT (andematunum@gmail.com)
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 

*/

#include "Bat.h"

/**
* file   Bat.cpp
* date   Sam 2 jan 2010 19:37:29 CET
* brief  TODO
*/

Bat::
Bat (int nchunks) {
  
  for (int k = 0; k < nchunks+2; k++) {
    if (k == 0) {
      parts_[k] = new BatPart(this, GAME_OBJECT_BAT_BORDER_LEFT);
      continue;
    }
    if (k == nchunks+1) {
      parts_[k] = new BatPart(this, GAME_OBJECT_BAT_BORDER_RIGHT);
      continue;
    }
    parts_[k] = new BatPart(this, GAME_OBJECT_BAT_CHUNK);
  }
  set_nchunks(nchunks);
  set_x_position((1024 - 32 + nchunks*16)/2);
  set_sticky(true);
}

Bat::
~Bat () {
  for (int k = 0; k < nchunks_+2; k++) {
    delete parts_[k];
  }
}

void
Bat::
set_x_position (int x) {
  x_ = x;
  SDL_Point pt = {x, BAT_Y};
  for (int k = 0; k < nchunks_+2; k++, pt.x += 16) {
    parts_[k]->set_position(pt);
  }
}

